<?php
/**
 * mt_rand() features in a lot of comments here. 
 * It is a good PRNG for Monte Carlo simulations, not for anything related to security. 
 * Wikipedia's page on cryptographically-secure PRNGs explains. 
 * If you want it to be hard for an attacker to guess or predict a "random" UUID, 
 * try using /dev/random instead.
 */


$r = unpack('v*', fread(fopen('/dev/random', 'r'),16));
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
    $r[1], $r[2], $r[3], $r[4] & 0x0fff | 0x4000, 
    $r[5] & 0x3fff | 0x8000, $r[6], $r[7], $r[8]);

echo $uuid;
